core: improve ReflectionLongAdderCounter performance#12542
core: improve ReflectionLongAdderCounter performance#12542shivaspeaks wants to merge 1 commit intogrpc:masterfrom
Conversation
|
It should not use reflection at runtime at all, with code structure like in #11977 |
|
I don't see a need to avoid reflection here, since the API is provided by the JDK there's no R8 -keep issue. Although maybe desugaring could make it useful to avoid the reflection. In any case, there's no evidence it is a problem right now. |
We can agree on that, however this code can be simplified by removing reflection. |
|
The reflection logic has been in vogue since 2017. In general we don't want to make changes unless there is a problem recognized with the code, which in this case doesn't exist. |
Avoid reflective access check in ReflectionLongAdderCounter.
The
ReflectionLongAdderCounteruses reflection to invoke theaddandsummethods ofjava.util.concurrent.atomic.LongAdder.Previously,
setAccessible(true)was not called on the reflectedMethodobjects. This resulted in a security access check being performed on every invocation, causing a performance penalty.This change calls
setAccessible(true)on theMethodobjects after they are retrieved, which bypasses the access check and improves performance.Fixes #12541
cc: @qsLI